package com.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 测试Controller用法
 * Created by Administrator on 2016/11/23.
 */
@Controller
@RequestMapping("/test")
public class TestController {

    @RequestMapping("/modelAndView")
    public ModelAndView testModelAndView(){

        Map<String, Object> context = new HashMap();
        context.put("name", "ModelAndView111");

        return new ModelAndView("/WEB-INF/jsp/modelAndView.jsp", context);
    }

    /**
     * 测试返回字符串
     * */
    @ResponseBody
    @RequestMapping(value = "/testReturnString")
    public String testReturnString(){
        return "false";
    }

    /**
     * 测试out.println内容
     * */
    @ResponseBody
    @RequestMapping(value = "/outprint")
    public void testOutprint(HttpServletResponse response) throws IOException {
        response.getOutputStream().print("111");
    }
}
